﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using Aulac.Global.Enums; using Aulac.Global.Data; using Aulac.Global.Common; using Aulac.Global.Xml;
using Aulac.Rsc.Ems; using Aulac.Rsc.Ems.Tags;
using System.Data;
using Aulac.Srv.Db.Provider; using Aulac.Srv.Db.Connect;
using Aulac.Srv.Db.Data.Catalogs;
using Aulac.Global.Exceptions;


namespace Aulac.Srv.Db.Data.Ems.Items.ItemType
{
    public class ClsTagStoreTypes: DbDataCatalogs
    {
        private List<string> mList = new List<string>(new string[]{tagItems.Store.TagStoreTypeID, tagItems.Store.TagStoreTypeName, tagItems.Store.TagStoreTypeEnum});
        
        public ClsTagStoreTypes(IDbAulacConnect pDb)
            : base(pDb, TableNames.Dm_TagStoreTypes, tagItems.Store.TagStoreTypeID, 
            new string[]{tagItems.Store.TagStoreTypeEnum, tagItems.Store.TagStoreTypeName}
            )
        {
            
        }
        protected override void OnGetListItem(ref DataTable pDataReturn, XmlDataDocument xmlParams)
        {
            try
            {
                string pCollection = XmlProcess.GetValueParam(xmlParams, tagItems.Store.CollectionTagStoreTypes);
                sqlQuery = string.Format("SELECT {0} FROM {1} ", StringHelper.ConvertArrayToString(", ", mList.ToArray()), TableNames.Dm_TagStoreTypes);
                sqlQuery += string.Format(" WHERE (N'{0}' = '' OR {1} IN ({2}))", pCollection, tagItems.Store.TagStoreTypeID, isEmpty( pCollection)? "0" : pCollection);
                DbDataProvider.ExecuteReaderDataToTable(mDbCmd, sqlQuery, ref pDataReturn);
            }
            catch (Exception ex)
            {
                throw new AulacException(this, "OnGetListItem", ex.Message);
            }
        }
    }
}
